Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly set CJS format, inputs when compiling #154

Merged
merged 1 commit into from
Aug 21, 2023
Merged

Conversation

jodyheavener
Copy link
Member

@jodyheavener jodyheavener commented Aug 21, 2023

Fixes #153

In #152 we stopped bundling all dependencies in the package. As it turns out, bundling was ensuring an all-CJS format and it was incorporating not only external deps but relative files. By removing bundling and not explicitly marking the format as CJS we inadvertently introduced ESM syntax and omitted relative files. More info here.

When the platform is set to node:

  • When bundling is enabled the default output format is set to cjs, which stands for CommonJS (the module format used by node). ES6-style exports using export statements will be converted into getters on the CommonJS exports object.

This package doesn't support ESM yet (at least not intentionally), so this PR:

  • Explicitly sets the format to CJS
  • Explicitly sets the two inputs to work with

Testing

You can test that this fix works by first cloning and setting up this repo:

git clone git@github.com:1Password/op-js.git
cd ./op-js && git checkout jh/fix-cjs
yarn && yarn build

Then you can also clone this test repo I set up:

git clone git@github.com:jodyheavener/tmp-opjs-test.git
cd ./tmp-opjs-test 
yarn && yarn start

This test repo has the op-js codebase symlinked as a dependency, so if you've built it locally everything should be working as expected. By comparison, if you were to repeat these steps in the op-js repo on main, it should fail.

Copy link
Collaborator

@chrisdunnbirch chrisdunnbirch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the test repo, that was really useful for quickly testing this one 🤩

I've tested main and this branch and the results were as expected, error on main and success on this branch.

@jodyheavener jodyheavener merged commit aced1a3 into main Aug 21, 2023
1 check passed
@jodyheavener jodyheavener deleted the jh/fix-cjs branch August 21, 2023 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants